package edu.dzxx.filter;

import edu.dzxx.pojo.User;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by ${纪雷} on 2020/04/23
 */

//@WebFilter(filterName = "loginWorker", urlPatterns = {"/manager/index.html","/"})
public class ManagerFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        HttpServletRequest req = (HttpServletRequest)request;
        HttpServletResponse res = (HttpServletResponse)response;
        User worker = (User) req.getSession().getAttribute("worker");
        if (worker != null) {
            chain.doFilter(request,response);
        }else {
            res.sendRedirect(req.getContextPath()+"/manager/login.html");
        }
    }

    @Override
    public void destroy() {

    }
}
